package pt.iscte.pcd.project.server;

import java.io.IOException;

import pt.iscte.pcd.project.order.Order;

public class DealWithClientReceiver extends Thread {

	private DealWithClient deal;


	public DealWithClientReceiver(DealWithClient deal) {
		this.deal=deal;
	}

	@Override
	public void run() {
		try {

			while (!isInterrupted()) {
				System.out.println("Waiting for orders from  Client"
						+deal.getSocketClient().toString());

				Order order = (Order) deal.getIn().readObject();
				System.out.println(order.toString());

				System.out.println("Received order from "
						+ deal.getSocketClient().toString());

				deal.adicionaPedidoAReceber(order);
				ServerWorker serverWorker = new ServerWorker(deal);
				deal.getThreadsInWait().add(serverWorker);
				serverWorker.start();
				
			}
		} catch (IOException e) {
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}


}
